package com.dfbz.demo03_多态的案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {
    public static void main(String[] args) {

      /*  Apple apple=new Apple();
        apple.benefit();

        Banana banana=new Banana();
        banana.benefit();

        System.out.println("---------------");*/

/*        Apple apple = new Apple();
        showAppleBenefit(apple);

        Banana banana=new Banana();
        showBananaBenefit(banana);*/


/*        Apple apple=new Apple();
        showFruitBenefit(apple);

        Banana banana=new Banana();
        showFruitBenefit(banana);*/


        // 多态
        Fruit fruit = new Apple();
        fruit.benefit();

    }

    // Fruit fruit = new Apple()
    // Fruit fruit = new Banana();
    public static void showFruitBenefit(Fruit fruit) {
        fruit.benefit();
    }

/*    public static void showAppleBenefit(Apple apple) {
        apple.benefit();
    }

    public static void showBananaBenefit(Banana banana) {
        banana.benefit();
    }*/
}

abstract class Fruit {

    // 水果的功效
    public abstract void benefit();
}

class Apple extends Fruit {

    @Override
    public void benefit() {
        System.out.println("苹果功效：生津止渴、健脾养心、补血安神");
    }
}

class Banana extends Fruit {

    @Override
    public void benefit() {
        System.out.println("香蕉功效：降血压、保护心血管、维持酸碱平衡、解酒");
    }
}